
var app = getApp();
Page({
  data: {
    mainView: 1,
    swiperCurrent: 0,
    swiperList: [getApp().globalData.source + "/ttbt_image_icon/generalize/1.png", getApp().globalData.source + "/ttbt_image_icon/generalize/2.png", getApp().globalData.source + "/ttbt_image_icon/generalize/3.png", getApp().globalData.source + "/ttbt_image_icon/generalize/4.png", getApp().globalData.source + "/ttbt_image_icon/generalize/5.png"],
    indicatorDots: false,
    autoplay: true,
    rulepopshow: false,
    circular: true
  },

  //轮播图的切换事件 
  swiperChange: function (e) {
    console.log(e);
    this.setData({
      swiperCurrent: e.detail.current //获取当前轮播图片的下标
    })
  },

  rulePopShow: function () {
    var that = this
    this.setData({
      rulepopshow: !that.data.rulepopshow
    })
  },
  rulePopHide: function (e) {
    var that = this
    this.setData({
      rulepopshow: !that.data.rulepopshow
    })

  },
  tabItemTap: function (e) {
	var that = this;
    var _dataSet = e.currentTarget.dataset;
    this.setData({
      mainView: _dataSet.view
    });
	var ck = _dataSet.view;
	  that.setData({
		  list: null
	  })
	if(ck=="1"){
		var parm = { "userId": wx.getStorageSync("userId"), orderType: "1" }
		that.findFriendsList(parm);//调用加载好友列表
	} else if (ck == "2"){
		var parm = { "userId": wx.getStorageSync("userId"), orderType: "2" }
		that.findFriendsList(parm);//调用加载好友列表
	} else if (ck == "3") {
		var parm = { "userId": wx.getStorageSync("userId"), orderType: "3" }
		that.findFriendsList(parm);//调用加载好友列表
	}
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	 var that = this;
	  that.findHomeInfo(); //调用加载基本信息
	  var parm = { "userId": wx.getStorageSync("userId"), orderType: "1" }
	  that.findFriendsList(parm);//根据参数调用加载好友列表、我的收益、和我的订单
  },

  //首页基本信息
  findHomeInfo:function(){
	  var that = this;
	  var parm = {"userId":wx.getStorageSync("userId")}
	  app.requestLoading(app.globalData.https + "distributionActivity/distribution/generalizeHome",
		  "get", parm, "加载中...",
		  function (res) {
			  var data = res[0]; 
			  if (data.code == "0") { 
				  // 获取系统信息   
				  var list = data.list[0]; 
				  that.setData({
					  dstributionInfo:list
				  })
			  }
		  } 
	  )
  },

	//加载数据的方法
	findFriendsList: function (parm) {
		var that = this;
		app.requestLoading(app.globalData.https + "distributionActivity/distribution/findGeneralizeFMO",
			"get", parm, "加载中...",
			function (res) {
				var data = res[0];
				if (data.code == "0") {
					// 获取系统信息   
					var list = data.list; 
					that.setData({
						list: list
					})
          if (list.length == 0) {
            that.setData({
              bottomtext: "暂无数据",
              showbottom: true
            })
          }else{
            that.setData({
              bottomtext: "暂无数据",
              showbottom: false
            })
          }
				}
			} 
		)
	},
  withdraw: function () {
    wx.navigateTo({
      url: '../commission_cash/commission_cash',
    })
  },
})